﻿/*
 * 文件名称：
 * 程序员：wangyun
 * 创建时间：2008/09/08
 * 
 * 功能说明：在线留言管理系统  
 * 
 * 修改人员：
 * 
 * 修改日期：
 * 
 * 修改记录：
 */

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Whir.Common.WebHelper;

public partial class Whir_System_Module_Reply_Default : System.Web.UI.Page
{
    protected int TypeID;
    protected string url;
    protected void Page_Load(object sender, EventArgs e)
    {
        RoleHelper.IsLogin();    //登录判断
        TypeID = NetRequest.GetQueryInt("TypeID");
        url = Server.HtmlEncode(NetRequest.GetUrl());
        if (!IsPostBack)
        {
            BindData();
        }
    }

    private void BindData()
    {
        TypeID = TypeID == 0 ? 2 : TypeID;
        DataSet ds = Whir.SQLServerDAL.DbHelperSQL.GetList("Whir_Reply", "ID", "*", AspNetPager1.PageSize, AspNetPager1.CurrentPageIndex - 1, "TypeID=" + TypeID, "", "CreateDate desc");
        int rowCount = int.Parse(ds.Tables[1].Rows[0][0].ToString());
        if (rowCount > 0)
        {
            AspNetPager1.RecordCount = rowCount;
            GridView1.DataSource = ds;
            GridView1.DataBind();
        }
        else
        {
            GridView1.Controls.Clear();
            divMessage.Visible = true;
        }
    }

    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        BindData();
    }

    protected void btnDelete_Click(object sender, EventArgs e)
    {
        Whir.BLL.Whir_Reply bll = new Whir.BLL.Whir_Reply();
        //获取被选中的编号
        int[] itemIds = this.GridView1.CheckedIndexs;
        if (itemIds.Length > 0)
        {
            foreach (int item in itemIds)
            {
                bll.Delete(item);
            }
            JsHelper.Alert(Page, "该记录已删除成功！");
            BindData();
        }
        else
        {
            JsHelper.Alert(Page, "请选择要删除的记录！");
        }
    }

    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if ("Show".IndexOf(e.CommandName) < 0) return;

        Whir.BLL.Whir_Reply bll = new Whir.BLL.Whir_Reply();
        GridViewRow row = ((LinkButton)e.CommandSource).Parent.Parent as GridViewRow;
        string InfoID = row.Cells[1].Text;
        Whir.Model.Whir_Reply model = bll.GetModel(int.Parse(InfoID));
        switch (e.CommandName)
        {
            case "Show"://审核
                if (bool.Parse(e.CommandArgument.ToString()))
                {
                    model.IsShow = false;
                }
                else
                {
                    model.IsShow = true;
                }
                bll.Update(model);
                break;
        }
        BindData();
    }
}
